#ifndef DIALOG_H
#define DIALOG_H

#include <QDialog>
#include <QSerialPort>
#include <QDateTime>
#include <QQueue>
#include <QPushButton>

namespace Ui {
class Dialog;
}

class Dialog : public QDialog//我们自己创建的dialog类 继承于QDialog类，我们的类的特点就是多了以下很多函数与属性
{
    Q_OBJECT//qt中的所有类都继承于此类

public://public函数
    explicit Dialog(QWidget *parent = nullptr);//构造函数必须public，以便外界调用
    void getconfig();
    ~Dialog();//析构函数必须public，以便外界调用
    void timerEvent(QTimerEvent *);
    char  XOR(QByteArray buf,uint8_t len);
    void clearAllvolLine();
    void clearAllpriLine();
    void clearAllpubLine();
    void clearAllidLine();
private slots://槽函数，class内部其他函数连接时调用
    void mytestslot();
    //combox复选框有变化时调用
    void on_comboBox_serialport_currentIndexChanged(const QString &arg1);

    void on_pushButton_open_clicked();//openbutton按下时调用

    void on_pushButton_send_clicked();//sendbutton按下调用
    void receivedata();//uart收到数据时调用
    void printFrame(QByteArray& ba);

    void on_pushButton_clicked();

private:
    void sendCmd(uint8_t cmd);

    Ui::Dialog *ui;//主界面ui对象
    QSerialPort  mSerialport;//包含QSerialPort模块后利用此模块可以创建具体的串口对象
    QDateTime current_date_time;

    struct cmd99info{
        float totalvol;
        int16_t curr;
        uint8_t soc;
        int8_t Tmos;
        int8_t Tenv;
        int8_t AvgTemp;
        uint8_t BatStatus;
        uint32_t TotalDsg;
        uint32_t TotalChg;
        uint16_t PreDsgTime;
        uint16_t CycTime;
        uint16_t BmsGuzhang;
        uint16_t BmsGaojing;
        uint8_t  mosStatus;
        uint32_t BalanceBit;
        uint32_t OvBit;
        uint32_t UvBit;
        uint16_t RemCap;
        uint8_t SOH;
        uint8_t cellNum;
        uint16_t cellVol[24];
        uint8_t tempNum;
        uint8_t cellTemp[10];
        uint32_t desCap;
        uint32_t fullCap;
        uint8_t premos;
        uint8_t heatmos;
        uint8_t Theat;
        uint8_t DET;
        uint16_t IN219Cur;
        uint8_t Relay;
        uint8_t BatType;
        uint16_t gain1;
        uint8_t  offset1;
        uint16_t gain2;
        uint8_t  offset2;
        uint16_t softVer;
        uint16_t hardVer;
        uint8_t  bootVer;
        uint16_t  FactoryCode;
        uint16_t  ProjectCode;
        uint8_t  ShortCnt;
        uint8_t  Uvcnt;
        uint8_t  ChgCnt;
        uint8_t  Cyccnt;
        uint8_t BatId[32];
    }cmd99info;

    int timer1;
    int sendcmdTimer;
    int handleDataTime;

    uint32_t clearTimeout=100;
    QQueue<unsigned char>  myqueue;//字节为单位的队列
    uint8_t vaildData[100];

    QPushButton pushButton_test;
};

#endif // DIALOG_H
